import six
from ipywidgets import (
    Widget, DOMWidget, widget_serialization, register
)
from ipywidgets.widgets.trait_types import TypedTuple
from traitlets import (
    Unicode, Int, CInt, Instance, ForwardDeclaredInstance, This, Enum,
    Tuple, List, Dict, Float, CFloat, Bool, Union, Any,
)

from {{ py_base_relative_path }}_base.Three import ThreeWidget
from {{ py_base_relative_path }}_base.uniforms import uniforms_serialization
from {{ py_base_relative_path }}enums import *
from {{ py_base_relative_path }}traits import *

from {{ superClass.pyRelativePath }} import {{ superClass.className }}

{{#each dependencies as |dep depName|}}
{{#notSuper dep.className}}
from {{ dep.pyRelativePath }} import {{ dep.className }}
{{/notSuper}}
{{/each}}

{{#unless hasOverride}}
@register
{{/unless}}
class {{ className }}({{ superClass.className }}):
    """{{ className }}

    Autogenerated by {{ generatorScriptName }}
    {{#if isCustom}}
    This class is a custom class for pythreejs, with no
    direct corresponding class in three.js.
    {{else}}
    See {{ threejs_docs_url }}
    {{/if}}
    """

    {{#if todo}}
    def __init__(self, **kwargs):
        raise NotImplementedError('{{ className }} is not yet implemented!')

    {{else}}
    {{#unless constructor.hasParameters}}
    def __init__(self, {{#each constructor.args as |arg|}}{{{ arg.name }}}{{#if arg.prop.defaultJson}}={{{ arg.prop.defaultJson }}}{{/if}}, {{/each}}**kwargs):
        {{#each constructor.args as |arg|}}
        kwargs['{{{ arg.name }}}'] = {{{ arg.name }}}
        {{/each}}
        super({{ className }}, self).__init__(**kwargs)

    {{/unless}}
    {{/if}}
    _model_name = Unicode('{{ modelName }}').tag(sync=True)

    {{#each properties as |prop propName|}}
    {{ propName }} = {{{ prop.trait_declaration }}}

    {{/each}}

if six.PY3:
    import inspect
    # Include explicit signature since the metaclass screws it up
    {{ className }}.__signature__ = inspect.signature({{ className }}.__init__)
